package com.hd.sup.modules.vehicle.wrapper;

import com.hd.common.constant.BizConstant;
import com.hd.common.page.BaseControllerWrapper;
import com.hd.common.utils.DateUtil;
import com.hd.common.utils.ValueUtils;

import java.util.Date;
import java.util.Map;

/**
 * @Project OPS设备运维平台
 * @Version: 1.0
 * @Author chentl
 * @Description: 车辆装饰器
 * @Pacakges: com.ops.modules.workflow.wrapper
 * @Create: 2020/12/8 0008 19:29
 */
public class VehicleWrapper extends BaseControllerWrapper {

    public VehicleWrapper(Object obj) {
        super(obj);
    }

    @Override
    protected void warpTheMap(Map<String, Object> map) {
        //格式化在线时长
//        Object duration = map.get("duration");
//        if (duration != null) {
//            BigDecimal seconds = new BigDecimal(ValueUtils.parseString(duration));
//            map.put("duration", DateUtil.transTime(seconds.longValue()));
//        }

        //上线时间
        Object online_time = map.get("online_time");
        if (online_time != null) {
            Date date = (Date) online_time;
            String dateStr = DateUtil.format(date, BizConstant.Common.DATE_FORMAT_SECOND.key());
            map.put("online_time", dateStr);
        }

        //离线时间
        Object off_time = map.get("last_logout_time");
        if (off_time != null) {
            Date now = new Date();
            Date date = (Date) off_time;
            String dateStr = DateUtil.format(date, BizConstant.Common.DATE_FORMAT_SECOND.key());
            map.put("off_time", dateStr);
            map.put("off_line_duration", DateUtil.transTime(ValueUtils.parseLong(DateUtil.getDiffSeconds(now, date))));
        }

        Object trans_type = map.get("trans_type");
        if (trans_type != null) {
            String str = ValueUtils.parseString(trans_type);
            map.put("trans_type", BizConstant.VehicleTransType.get(str));
        }

    }
}